import { defineStore } from 'pinia'
import { ref } from 'vue'

export const userStore = defineStore(
  'user',
  () => {
    const userInfo = ref(null) // 初始化 userInfo

    const setUserInfo = (val) => {
      userInfo.value = val
    }

    const clearUserInfo = () => {
      userInfo.value = null
    }

    return { userInfo, setUserInfo, clearUserInfo }
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key) // 修正方法名
        },
        setItem(key, value) {
          uni.setStorageSync(key, value) // 修正方法名
        }
      }
    }
  }
)
